<template>
  <el-table :data="tableData" style="width: 100%">
<!--  prop=property 设置当前列的内容为数组中对象的某个属性  -->
    <el-table-column prop="date" label="Date" width="180" />
    <el-table-column prop="name" label="Name" width="180" />
    <el-table-column prop="address" label="Address" />
  </el-table>
  <h3>自己的员工列表</h3>
  <el-table :data="arr" stripe >
    <el-table-column type="index" label="编号" width="80px"></el-table-column>
    <el-table-column prop="name" label="名字" width="100px"></el-table-column>
    <el-table-column prop="salary" label="工资"></el-table-column>
    <el-table-column prop="job" label="工作"></el-table-column>
<!--  自定义列开始  -->
    <el-table-column label="操作">
<!--   scope变量中装着当前行对应的数据, scope.$index 当前行对应的下标
    scope.row当前行对应的数组中的对象 -->
      <template #default="scope">
        <el-button size="small" type="danger"
            @click="handleDelete(scope.$index, scope.row)">Delete</el-button>
      </template>
    </el-table-column>
<!--  自定义列结束  -->
  </el-table>

</template>

<script setup>

import {ref} from "vue";

const handleDelete = (i,emp)=>{
  if (confirm("您确认删除"+emp.name+"吗?")){
    arr.value.splice(i,1);
  }
}
const arr = ref([{name:"张三",salary:3000,job:"销售"},
  {name:"李四",salary:4000,job:"人事"},
  {name:"王五",salary:5000,job:"程序员"},{name:"张三",salary:3000,job:"销售"},
  {name:"李四",salary:4000,job:"人事"},
  {name:"王五",salary:5000,job:"程序员"}]);

const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
</script>
